package com.hopes.bizz.risk.control.evaluate;

import com.hopes.bizz.risk.control.bo.NegatedItem;
import com.hopes.bizz.risk.control.bo.RiskEffectEvaluationScore;
import com.hopes.bizz.risk.control.bo.RiskEvaluateBo;

/**
 * @author lyb
 * @version 1.0
 * @date 2023/7/5
 */
public abstract class RiskRejectFactorHandler {

    private RiskRejectFactorHandler nextHandler;

    protected static final String LINE_SEPARATOR = "<br/>";

    protected NegatedItem calculate(RiskEvaluateBo riskEvaluateBo, NegatedItem negatedItem) {
        RiskEffectEvaluationScore riskEffectEvaluationScore = riskEvaluateBo.getRiskEffectEvaluationScore();
        if (isUse(riskEffectEvaluationScore)) {
            return doCalculate(riskEvaluateBo, negatedItem);
        }
        return doNextCalculate(riskEvaluateBo, negatedItem);
    }

    abstract protected Boolean isUse(RiskEffectEvaluationScore riskEffectEvaluationScore);

    abstract protected NegatedItem doCalculate(RiskEvaluateBo riskEvaluateBo, NegatedItem negatedItem);

    protected NegatedItem doNextCalculate(RiskEvaluateBo riskEvaluateBo, NegatedItem negatedItem) {
        if (nextHandler == null) {
            // 所有否决因子都执行完没结束，返回 1
            return negatedItem;
        }
        return nextHandler.calculate(riskEvaluateBo, negatedItem);
    }

    public void setNextHandler(RiskRejectFactorHandler nextHandler) {
        this.nextHandler = nextHandler;
    }
}
